let express = require('express')
var cors = require('cors')
var router = require("./router/router")
const app = express()
const port = 3001
app.use(cors())
app.use('/uploads', express.static('uploads'))
app.use(router)

//404页面
app.use((req,res,next)=>{
    let err = new Error('Not Found')
    err.status = 404
    next(err)
})

//出现错误处理
app.use((err,req,res,next)=>{
    console.log(err)
    res.status(err.status  || 500)
    res.send(err.message)
})

app.listen(port, () => {
    console.log('服务器开启中')
})
